<template>
  <el-main>
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="借贷款方">
        <el-input v-model="queryForm.daiMingch" placeholder="借贷款方"></el-input>
      </el-form-item>
      <el-form-item label="贷款时间">
        <el-date-picker
            v-model="queryForm.shiJianStart"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="开始时间">
        </el-date-picker>
        <el-date-picker
            v-model="queryForm.shiJianEnd"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
        :data="tableData"
        style="width: 100%"
        :row-class-name="tableRowClassName">
      <el-table-column
          prop="name"
          label="序号"
          width="50">
        <template slot-scope="scope">
          {{scope.$index+1}}
        </template>
      </el-table-column>
      <el-table-column
          prop="daiMingch"
          label="贷方"
          width="180">
      </el-table-column>
      <el-table-column
          prop="jieMingch"
          label="借款方"
          width="180">
      </el-table-column>
      <el-table-column
          prop="shiJian"
          label="合同日期"
          width="180">
      </el-table-column>
      <el-table-column
          prop="jiner"
          label="合同金额">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="danger"
              @click="detail(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
          layout="prev, pager, next"
          @current-change="currentPage"
          :page-count="pages">
      </el-pagination>
    </div>
    <el-row>
      <el-col :span="6">
        <el-button type="primary" @click="pdf">导出pdf</el-button>
        <el-button type="primary" @click="opendialog">添加</el-button>
      </el-col>
    </el-row>


    <el-dialog
        title="添加"
        :visible.sync="dialogVisible"
        width="70%">
      <span>
        <el-form label-position="left" label-width="80px">
          <el-form-item label="贷款方方">
            <el-input v-model="saveForm.daiMingch"></el-input>
          </el-form-item>
          <el-form-item label="借款方">
            <el-input v-model="saveForm.jieMingch"></el-input>
          </el-form-item>
          <el-form-item label="借款金额">
            <el-input v-model="saveForm.jiner" max="9999999" min="0"></el-input>
          </el-form-item>
          <el-form-item label="借款时间">
            <el-date-picker
                v-model="saveForm.shiJian"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="开始时间">
        </el-date-picker>
          </el-form-item>
          <el-form-item label="借款时间">
            <!--<uploader :options="options" @fileSucess="fileSucess"></uploader>-->
            <uploader :options="options" class="uploader-example" @file-success="fileSucess">

            </uploader>
          </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </span>
    </el-dialog>


    <el-dialog
        title="详情"
        :visible.sync="dialogVisible1"
        width="70%">
      <span>
        {{hetong.id}} <br>
         {{hetong.daiMingch}} <br>
         {{hetong.jieMingch}} <br>
         {{hetong.jiner}} <br>
         {{hetong.shiJian}} <br>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">取 消</el-button>
      </span>
    </el-dialog>



  </el-main>
</template>

<script>
export default {
  name: "HeTong",
  data() {
    return {
      options:{
        target: this.axios.defaults.baseURL + 'fujian/upload',
        testChunks: false,
      },
      attrs: {
        accept: 'image/*'
      },
      tableData: [],
      queryForm:{
        current:1,
        size:1
      },
      pages:0,
      dialogVisible: false,
      dialogVisible1:false,
      saveForm:{

      },
      hetong: {}
    }
  },
  methods: {
    detail(id) {
      // console.log("id:{}", id);
      this.dialogVisible1 = true;
      this.axios.get('/hetong/detail',{params:{id: id}}).then(res=>{
        this.hetong = res.data.data;
      })
    },
    save() {
      this.axios.post('hetong/save',this.saveForm).then(res=>{
        if (res.data.code == 500) {
          this.$message.error(res.data.msg);
          return;
        }
        this.dialogVisible = false;
        this.pageQuery();
      })
    },
    fileSucess(p1,p2,p3) {
      console.log(p3)
      let res = JSON.parse(p3);
      this.saveForm.fujianId = res.data;
    },
    opendialog() {
      this.dialogVisible = true;
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    pdf() {
      window.open(this.axios.defaults.baseURL + 'hetong/pdfDown', '_blank');
    },
    currentPage(current) {
      console.log(current);
      this.queryForm.current = current;

      this.pageQuery();
    },
    onSubmit() {
      this.queryForm.current = 1;
      this.pageQuery();
    },

    check(row) {
      this.axios.get('contract/startProcessInstanceById', {params: {id: row.id}}).then(res => {
        this.$message.success('已提交审核');
      });

    },

    pageQuery() {
      this.axios.get('/hetong/page', {params: this.queryForm}).then(res => {
        this.tableData = res.data.data.records;
        this.pages = res.data.data.pages;
      });
    }
  },
  mounted() {
    this.pageQuery();
  }
}
</script>

<style scoped>
.el-row {
  margin-top: 20px;
}
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
.uploader-example {
  width: 480px;
  padding: 15px;
  margin: 40px auto 0;
  font-size: 12px;
  box-shadow: 0 0 10px rgba(0, 0, 0, .4);
}
.uploader-example .uploader-btn {
  margin-right: 4px;
}
.uploader-example .uploader-list {
  max-height: 440px;
  overflow: auto;
  overflow-x: hidden;
  overflow-y: auto;
}
</style>